package com.alongstudio.account.action;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.alongstudio.account.action.base.BaseAction;
import com.alongstudio.account.commons.exception.BusinessException;
import com.alongstudio.account.constants.SystemConstant;
import com.alongstudio.account.entity.ClientUser;
import com.alongstudio.account.service.IClientUserService;

@SuppressWarnings("serial")
@Component("ClientLoginAction")
@Scope("prototype")
public class ClientLoginAction extends BaseAction {
	@Autowired
	private IClientUserService userService;
	private String userName;
	private String password;
	private List<ClientUser> userList;
	private String errorMsg;//错误信息
	
	@Override
	public String executeAction() throws BusinessException {

		return SUCCESS;
	}


	/**
	 * 校验登录用户
	 * @return
	 * @throws Exception
	 */
	public String checkLogin() throws Exception {
		try {
			ClientUser user = userService.checkUserLogin(userName, password);// MD5Crypt.getMD5(password)
			if (user != null) {
				errorMsg = "error";
				setSessionAttribute(SystemConstant.SESSION_USER_ID, user.getId());
				setSessionAttribute(SystemConstant.SESSION_USER_NAME, user.getUserName());
				return SUCCESS;
			}
		}
		catch(Exception e){
			e.printStackTrace();
		}
		return INPUT;
	}
	
	/**
	 * 分页数据
	 * @return
	 * @throws Exception
	 */
	public String getUserForPage() throws Exception{
//		String b=null;
//		System.out.println(b.length());
		total = 1;
		userList = userService.findUserByPage(new HashMap(), start, pageSize);
		
		return SUCCESS;
	}

	public List<ClientUser> getUserList() {
		return userList;
	}

	public void setUserList(List<ClientUser> userList) {
		this.userList = userList;
	}
	
	public String getErrorMsg() {
		return errorMsg;
	}

	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

}
